﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BUS;
namespace QuanLyThuVien
{
    /// <summary>
    /// Lớp kiểm tra tính thỏa mãn các yêu cầu trước khi xử lý
    /// </summary>
    public class Regulations
    {
        static ThamSoBUS thamSo = new ThamSoBUS();
        public static bool EligibleDocGia(DateTime NgaySinh, DateTime NgayLapThe)
        {
            if (NgayLapThe.Year - NgaySinh.Year < thamSo.GetGiaTriThamSo(thamSo.TuoiToiThieu)
                || NgayLapThe.Year - NgaySinh.Year > thamSo.GetGiaTriThamSo(thamSo.TuoiToiDa))
            {
                return false;
            }
            return true;
        }

        public static bool EligibleSach(int NamXB)
        {
            if (NamXB > thamSo.GetGiaTriThamSo(thamSo.KCNamXB) || NamXB > DateTime.Today.Year)
            {
                return false;
            }
            return true;
        }

        public static bool EligibleTheDocGia(DateTime NgayHetHanThe)
        {
            if (DateTime.Today.Date >= NgayHetHanThe.Date)
            {
                return false;
            }
            return true;
        }
        public static bool EligibleNamXB(int NamXB)
        {
            if (DateTime.Today.Year - NamXB > thamSo.GetGiaTriThamSo(thamSo.KCNamXB))
                return false;
            return true;
        }

        public static bool EligibleDocGia_SachMuonToiDa(int MaDG, int SoLuongSachMuonThem)
        {
            DocGiaBUS docGiaBUS = new DocGiaBUS();
            int sl = docGiaBUS.GetSoLuongCuonSachDangMuon(MaDG);
            if (sl + SoLuongSachMuonThem > thamSo.GetGiaTriThamSo(thamSo.SoSachMuonToiDa))
                return false;
            return true;
        }

        public static bool EligibleDocGia_SachMuonQuaHan(int MaDG)
        {
            CuonSachBUS cuonSachBUS = new CuonSachBUS();
            int slMuonQuaHan = cuonSachBUS.GetListCuonSachMuonQuaHanByDocGia(MaDG).Count;
            if (slMuonQuaHan > 0)
                return false;
            return true;
        }

    }
}
